package com.heaboy.feedback.websocket.handler;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.heaboy.feedback.websocket.WsWebSocketHandler;
import com.heaboy.feedback.websocket.domain.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TeacherMessageHandler implements MessageHandler{

    @Autowired
    private WsWebSocketHandler wsWebSocketHandler;
    @Override
    public void handle(Message msg) {
        switch (msg.getType()) {
            case 0:
                //签到
                break;
            case 1:
                //常见问题
                break;
            case 2:
                //自定义问题
                break;
            default:
        }
        ObjectMapper mapper = new ObjectMapper();
        try {
            String s = mapper.writeValueAsString(msg);
            wsWebSocketHandler.sendToStudent(msg.getLessonId().toString(),s);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
//            throw new RuntimeException(e);
        }

    }
}
